#include "mainwindow.h"
#include <QMenubar>
#include <QAction>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QSplitter>
#include <QObject>
#include <QScrollBar>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{

    //setFocusPolicy(Qt::StrongFocus);
    //添加exit功能
    Action_exit = new QAction(tr("E&xit"), this);
    Action_exit->setShortcuts(QKeySequence::Quit);
    Action_exit->setStatusTip(tr("Exit the application"));
    connect(Action_exit, SIGNAL(triggered()), this, SLOT(close()));
    //添加file菜单及exit功能
    Menu_file = menuBar()->addMenu(tr("&File"));
    Menu_file->addAction(Action_exit);
    //添加view
    QGraphicsScene *Scene=new QGraphicsScene(this);

    for(int i=0;i<5;i++)
    {
        CandleStick *candlestick=new CandleStick(20,30,40,10);
        Scene->addItem(candlestick);
        candlestick->setPos(80*i,30);
    }

    Coordinate *coordinate=new Coordinate();
    Scene->addItem(coordinate);

    ChartView *View=new ChartView(Scene);
    //View->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    QGraphicsScene *Scene2=new QGraphicsScene(this);
    //Scene2->addRect(0,0,200,200);
    ChartView *View2=new ChartView(Scene2);

    ChartSplitter *splitter=new ChartSplitter(this);

    splitter->addWidget(View);
    splitter->addWidget(View2);
    setCentralWidget(splitter);
    connect(splitter,SIGNAL(zoomin()),View,SLOT(zoomin()));
    connect(splitter,SIGNAL(zoomout()),View,SLOT(zoomout()));
    connect(splitter,SIGNAL(zoomin()),View2,SLOT(zoomin()));
    connect(splitter,SIGNAL(zoomout()),View2,SLOT(zoomout()));

    connect(View->horizontalScrollBar(), SIGNAL(valueChanged(int)),
            View2, SLOT(move(int)));
    connect(View2->horizontalScrollBar(), SIGNAL(valueChanged(int)),
            View, SLOT(move(int)));



}

MainWindow::~MainWindow()
{
    
}
